package com.yingjia.yingjiauniversity.http;

import android.support.annotation.NonNull;

import com.yingjia.yingjiauniversity.base.BaseEntry;
import com.yingjia.yingjiauniversity.base.BaseObserver;
import com.yingjia.yingjiauniversity.bean.base.SignatureEntity;
import com.yingjia.yingjiauniversity.http.exception.BaseException;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * 对请求成功返回数据处理
 *
 * @author mars.yu
 * @date 2017/12/08
 */
public abstract class HttpObserver<T> extends BaseObserver<T> {

    public HttpObserver(CompositeDisposable compositeDisposable) {
        super(compositeDisposable);
    }

    @Override
    public void onSubscribe(@NonNull Disposable disposable) {
        super.onSubscribe(disposable);
        onStart(disposable);
    }

    @Override
    public void onErr(BaseException var1) {
        onError(var1);
    }

    @Override
    public void onSuc(BaseEntry<T> var1) {
        onSucess((SignatureEntity<T>) var1);
    }

    public abstract void onError(BaseException baseException);

    public abstract void onSucess(BaseEntry<T> baseEntry);

    /**
     * 开始请求.
     *
     * @param d the d
     */
    protected void onStart(Disposable d) {
    }

    ;

    @Override
    public void onComplete() {

    }
}
